package com.lv.leyou.web;


import com.lv.leyou.dto.CategoryDTO;
import com.lv.leyou.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //根据ids集合查询分类
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryGategoryByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(CategoryDTO.convertEntityList(categoryService.querylistByIds(ids)));
    }

    //根据id查询分类
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryGategoryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(new CategoryDTO(categoryService.queryGategoryById(id)));
    }

    //根据父类目id查询子分类
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryGategoryByParentid(@RequestParam("pid") Long pid) {
        return ResponseEntity.ok(CategoryDTO.convertEntityList(this.categoryService.queryGategoryByParentid(pid)));

    }

    //根据品牌id去查询分类
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryGategroupByBandId(@RequestParam("id") Long brandId) {
        return ResponseEntity.ok(this.categoryService.queryGategroupByBandId(brandId));
    }

}